package com.ruoyi.plan.controller;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.enums.FitnessStatus;
import lombok.SneakyThrows;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.plan.domain.StarsPlanFitness;
import com.ruoyi.plan.service.IStarsPlanFitnessService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * fitnessController
 * 
 * @author ysz
 * @date 2022-05-25
 */
@Controller
@RequestMapping("/plan/fitness")
public class StarsPlanFitnessController extends BaseController
{
    private String prefix = "plan/fitness";

    @Autowired
    private IStarsPlanFitnessService starsPlanFitnessService;

    @RequiresPermissions("plan:fitness:view")
    @GetMapping()
    public String fitness(ModelMap mmap)
    {
        startPage();
        Map map = starsPlanFitnessService.selectStarsPlanFitnessList();
        mmap.put(FitnessStatus.ALL.getName(), map.get(FitnessStatus.ALL.getName()));
        mmap.put(FitnessStatus.PROCESSED.getName(),map.get(FitnessStatus.PROCESSED.getName()));
        mmap.put(FitnessStatus.FINISHED.getName(),map.get(FitnessStatus.FINISHED.getName()));
        return prefix + "/fitness1";
    }

//    /**
//     * 导出fitness列表
//     */
//    @RequiresPermissions("plan:fitness:export")
//    @Log(title = "fitness", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    @ResponseBody
//    public AjaxResult export(StarsPlanFitness starsPlanFitness)
//    {
//        List<String> list = starsPlanFitnessService.selectStarsPlanFitnessList(starsPlanFitness);
//        ExcelUtil<StarsPlanFitness> util = new ExcelUtil<StarsPlanFitness>(StarsPlanFitness.class);
//        return util.exportExcel(list, "fitness数据");
//    }

    /**
     * 新增fitness
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存fitness
     */
    @RequiresPermissions("plan:fitness:add")
    @Log(title = "fitness", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StarsPlanFitness starsPlanFitness)
    {
        starsPlanFitness.setCreateUser(getSysUser().getUserId());
        return toAjax(starsPlanFitnessService.insertStarsPlanFitness(starsPlanFitness));
    }

    /**
     * 修改fitness完成状态
     */
    @RequiresPermissions("plan:fitness:updateFitnessStatus")
    @Log(title = "fitness", businessType = BusinessType.INSERT)
    @PostMapping("/updateFitnessStatus")
    @ResponseBody
    public AjaxResult updateFitnessStatus(Long id)
    {
        return toAjax(starsPlanFitnessService.updateFitnessStatus(id));
    }

    @RequiresPermissions("plan:fitness:refreshFitness")
    @Log(title = "fitness", businessType = BusinessType.INSERT)
    @PostMapping("/refreshFitness")
    public String refreshFitness(String fragment,ModelMap mmap) {
        Map map = starsPlanFitnessService.selectStarsPlanFitnessListByStatus(fragment);
        mmap.put(FitnessStatus.valueOf(fragment.toUpperCase()).getName(), map.get(FitnessStatus.valueOf(fragment.toUpperCase()).getName()));
        return prefix + "/fitness1::" + fragment;
    }

    /**
     * 修改fitness
     */
    @RequiresPermissions("plan:fitness:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        StarsPlanFitness starsPlanFitness = starsPlanFitnessService.selectStarsPlanFitnessById(id);
        mmap.put("starsPlanFitness", starsPlanFitness);
        return prefix + "/edit";
    }

    /**
     * 修改保存fitness
     */
    @RequiresPermissions("plan:fitness:edit")
    @Log(title = "fitness", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StarsPlanFitness starsPlanFitness)
    {
        return toAjax(starsPlanFitnessService.updateStarsPlanFitness(starsPlanFitness));
    }

    /**
     * 删除fitness
     */
    @RequiresPermissions("plan:fitness:remove")
    @Log(title = "fitness", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(starsPlanFitnessService.deleteStarsPlanFitnessByIds(ids));
    }
}
